package com.zhuqi.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author zhuqi
 * @version 1.0
 * @date 2021/3/25 19:37
 */
@Controller
public class UserController {

    @GetMapping("query")
    @PreAuthorize("hasAuthority('user:query')")
    public String query(){
        return "user/query";
    }

    @GetMapping("add")
    @PreAuthorize("hasAuthority('user:add')")
    public String add(){
        return "save";
    }

    @GetMapping("update")
    @PreAuthorize("hasAuthority('user:update')")
    public String update(){
        return "user/update";
    }

    @GetMapping("delete")
    @PreAuthorize("hasAuthority('user:delete')")
    public String delete(){
        return "user/delete";
    }

    @GetMapping("export")
    @PreAuthorize("hasAuthority('user:export')")
    public String export(){
        return "user/export";
    }

    /**
     * 获取角色信息
     * @return
     */
    @ResponseBody
    @GetMapping("geyUserInfo")
    public Authentication getUserInfo(){
        return SecurityContextHolder.getContext().getAuthentication();
    }
}
